import java.util.Arrays;

/**
 * Created with IntelliJ IDEA
 * Description
 * User: 王杰
 * Date: 2025-05-30
 * Time: 13:42
 */
public class MyStack {
    public int[] elem;
    public int usedSize;

    public MyStack() {
        this.elem = new int[10];
    }

    public void push(int val) {
        if (isFull()) {
            this.elem = Arrays.copyOf(elem, 2 * elem.length);
        }
        elem[usedSize++] = val;
    }

    public boolean isFull() {
        return usedSize == elem.length;
    }

    public int pop() {
        if (isEmpty()) {
            throw new EmptyStackException();
        }
        int val = elem[usedSize - 1];
        usedSize--;
        return val;
    }

    public int peek() {
        if (isEmpty()) {
            return -1;
        }
        return elem[usedSize - 1];
    }

    public boolean isEmpty() {
        return usedSize == 0;
    }


}
